﻿Import-Module -Force ..\ConfigurationDatabase\libConfigurationDatabase.psm1

$scriptEnvironmentShortName="QA6"

$crashDumpArchivePath=(Get-ConfigurationSetting -environmentShortName $environmentShortName -scope "Global"  -name "CrashDumpArchivePath").Value

workflow Analyze-CrashDump($crashDumpArchivePath)
{

    $crashDumps=Get-ChildItem $crashDumpArchivePath\*.dmp

    foreach -Parallel($crashDump in $crashDumps)
    {
        $crashDumpAnalysisLogPath=$crashDump.FullName.Replace(".DMP",".log")
        if(-not(Test-Path $crashDumpAnalysisLogPath))
        {
            Write-Output "Analyzing crash dump $crashDumpAnalysisLog"
            InlineScript {& 'C:\Program Files (x86)\Windows Kits\8.1\Debuggers\x64\cdb.exe' -y SRV*c:\symbols*http://msdl.microsoft.com/download/symbols -z $Using:crashDump.FullName -cfr c:\codePlex\windows\analyzeCrash.cdb -logo $Using:crashDumpAnalysisLogPath }
        }
        else
        {
            Write-Output $crashDump.FullName"was already analyzed,skipping."
        }
    }

}

Analyze-CrashDump -crashDumpArchivePath $crashDumpArchivePath